package com.example.pma.controllers;

import com.example.pma.dao.ForumRepository;
import com.example.pma.dao.ResumeRepository;
import com.example.pma.entities.Forum;
import com.example.pma.entities.Resume;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;


@Controller
@RequestMapping("forums")
public class ForumController{

    @Autowired
    ForumRepository forumRepository;


    @GetMapping
    public String displayForum(Model model){

        List<Forum> forums = forumRepository.findAll();
        model.addAttribute("forums",forums);
        return "forums/list-forums";
    }

    @GetMapping("/new")
    public String displayForumForm(Model model){
        Forum aForum=new Forum();
        model.addAttribute("forum",aForum);
        return "forums/new-forum";
    }

    @PostMapping("/save")
    public String createForum(Model model, Forum forum){
        forumRepository.save(forum);
        return "redirect:/forums";

    }
}
